<template>
    <view>
        <ss-preview :fileUrl="fileUrl" :fileType="fileType"></ss-preview>
    </view>
</template>

<script>
import { prevPdf } from '@/api/http'
export default {
    data() {
        return {
            fileUrl: '',
            fileType: ''
        }
    },
    onLoad(option) {
        let options = JSON.parse(decodeURIComponent(option.item))
        if (options.type == 4) {
            this.getFiles(options.fileName)
        } else {
            this.fileType = options.type;
            this.fileUrl = options.src;
        }
    },
    methods: {
        async getFiles(fileName) {
            const res = await prevPdf(fileName)
            //下面代码将base64转换成blob,
            var bstr = atob(res);
            var n = bstr.length;
            var u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n);
            }
            var pdf = new Blob([u8arr], {
                type: 'application/pdf'
            });
            let url = URL.createObjectURL(pdf)
            this.fileType = '4';
            this.fileUrl = url;
        },

    }


}
</script>

<style></style>
